package com.cn.kehong.controller;


import com.cn.kehong.api.IOeeService;
import com.cn.kehong.domain.Oee;
import com.cn.kehong.domain.OeeVo;
import com.cn.kehong.domain.OeeWorkshopRate;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/oee")
public class OeeController {

    @Autowired
    private IOeeService iOeeService;

    //初始化oee编制列表页面
    @RequestMapping("/getOeeOrganization/{frontToken}")
    @ResponseBody
    public JsonResponse<List<OeeVo>> getOeeOrganization(@PathVariable(value = "frontToken", required = true) String frontToken, QueryForm queryForm) throws Exception {
        JsonResponse<List<OeeVo>> response = new JsonResponse<>();
        List<OeeVo> oeeVos = iOeeService.getOeeOrganization(queryForm);
        response.setResult(oeeVos);
        response.setSuccess(true);
        return response;
    }


    //oee新增接口
    @RequestMapping("/addOeeOrganization/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addOeeOrganization(@RequestBody Oee oee, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = iOeeService.addOeeOrganization(oee);
        return CommonUtil.getResponseData(response,result);
    }




     //oee删除接口
    @RequestMapping("/deleteOeeOrganization/{frontToken}")
    @ResponseBody
    public JsonResponse<String> deleteOeeOrganization(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = iOeeService.deleteOeeOrganization(queryForm);
        return CommonUtil.getResponseData(response,result);
    }


    //oee修改接口
    @RequestMapping("/updateOeeOrganization/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateOeeOrganization(@RequestBody Oee oee, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = iOeeService.updateOeeOrganization(oee);
        return CommonUtil.getResponseData(response,result);
    }



    //初始化oee周报列表页面
    @RequestMapping("/getOeeWeekly/{frontToken}")
    @ResponseBody
    public JsonResponse<List<OeeWorkshopRate>> getOeeWeekly(@PathVariable(value = "frontToken", required = true) String frontToken, QueryForm queryForm) throws Exception {
        JsonResponse<List<OeeWorkshopRate>> response = new JsonResponse<>();
        List<OeeWorkshopRate> oeeWorkshopRates = iOeeService.getOeeWeekly(queryForm);
        response.setResult(oeeWorkshopRates);
        response.setSuccess(true);
        return response;
    }

    //初始化oee月报列表页面
    @RequestMapping("/getOeeMonth/{frontToken}")
    @ResponseBody
    public JsonResponse<List<OeeWorkshopRate>> getOeeMonth(@PathVariable(value = "frontToken", required = true) String frontToken, QueryForm queryForm) throws Exception {
        JsonResponse<List<OeeWorkshopRate>> response = new JsonResponse<>();
        List<OeeWorkshopRate> oeeWorkshopRates = iOeeService.getOeeMonth(queryForm);
        response.setResult(oeeWorkshopRates);
        response.setSuccess(true);
        return response;
    }

}
